package com.itboye.mengwu.app.ui.mymeng;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.core.alert.ByAlert;
import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.object.SpPublicParams;
import com.itboye.core.utils.SPUtils;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.login.ui.LoginActivity;
import com.itboye.mengwu.data.model.MessgeBean;
import com.itboye.mengwu.data.presenter.MessgePresenter;

public class MessageActivity extends BaseActivity implements OnClickListener,
		Observer {
	RelativeLayout layoutQuan, layoutGuanzhu, layouMessge, lalatiPrivate,
			reOrder;
	ImageView back;
	TextView txt_title;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_messge;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		txt_title.setText("消息中心");
		Intent intent = new Intent("readed");
		sendBroadcast(intent);
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.layoutQuan:
			if (judgeLogin()) {
				Intent intent = new Intent(this, ActivityQuanMessge.class);// 圈消息
				startActivity(intent);
			}
			break;
		case R.id.layoutGuanzhu:
			if (judgeLogin()) {
				Intent guanzhu = new Intent(this, ActivityGuanZhu.class);// 关注
				startActivity(guanzhu);
			}

			break;
		case R.id.layouMessge:
			Intent msg = new Intent(this, MegActivity.class);
			startActivity(msg);
			break;
		case R.id.lalatiPrivate:
			if (judgeLogin()) {
				Intent privateLiite = new Intent(this,
						PrivateLtterActivity.class);// 私信
				startActivity(privateLiite);
			}

			break;
		case R.id.back:
			finish();
			break;
		case R.id.reOrder:
			if (judgeLogin()) {
				Intent order = new Intent(this, OrderMessageActivity.class);// 订单消息界面
				startActivity(order);
			}

			break;
		default:
			break;
		}
	}

	public void onMessge() {
		ByAlert.alert("点击了");
		MessgePresenter messgePresenter = new MessgePresenter(this);
		MessgeBean bean = new MessgeBean();
		bean.setUid((String) SPUtils.get(this, null, SpPublicParams.UID, ""));
		bean.setMsg_type("msg_type");// (title);
		messgePresenter.add(bean);
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		ByAlert.alert("werwerwee" + entity.getData());
	}

	public boolean judgeLogin() {
		if (SPUtils.get(MessageActivity.this, null, SpPublicParams.UID, "")
				+ "" == null
				|| (SPUtils.get(MessageActivity.this, null, SpPublicParams.UID,
						"") + "").equals("")) {
			Intent intent = new Intent(MessageActivity.this,
					LoginActivity.class);
			startActivity(intent);
			return false;
		} else {
			return true;
		}
	}
}
